import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'
import classNames from 'classnames'
import styles from './index.module.scss'
import { formatTime } from "@/utils/utils"
import OrderCardGoods from "@/components/order/cart-goods"

interface IProps {
  className: string
  order: any
  onClick: any
}

export default class OrderCardBody extends Component<IProps, {}> {
  props: any

  render() {
    const prefixCls = 'order-body'
    const { className, order={}, onClick } = this.props
    return order.id && (
      <View className={classNames(styles[prefixCls], 'thin-border__b', className)} onClick={() => onClick && onClick()}>
        <View className={styles[`${prefixCls}-goods-list`]}>
          {order.cartSnap.map(cart => {
            return (<OrderCardGoods key={cart.id} info={cart} className={styles[`${prefixCls}-goods-item`]}/>)
          })}
        </View>
        <View className={styles[`${prefixCls}-item`]}>
          <View className={styles[`${prefixCls}-item-time`]}>下单日期：{formatTime(order.createdAt, 'YYYY-MM-DD HH:mm')}</View>
          <View className={styles[`${prefixCls}-item-amount`]}>共 {order.cartSnap.length} 件商品 合计：￥{order.payAmount}</View>
        </View>
      </View>
    )
  }
}
